package javabook.ch07;

import java.awt.Button;
import java.awt.Canvas;
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.Choice;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.List;
import java.awt.Scrollbar;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

public class todo03 extends Frame implements ActionListener, ItemListener, AdjustmentListener{
	
	Label label1, lb0;
	Canvas imgCanvas;
	Button bt0;
	List list;
	
	public todo03(){
		super ("단순 컴포넌트 - 체크박스와 라디오 버튼/ 리스트와 초이스 / 수직 및 수평 스크롤바 / 이미지 캔버스 ");
		setLayout(new FlowLayout());
		
		list = new List(3, false);
		list.add("천안");
		list.add("당진");
		list.add("속초");
		list.add("서울");
		list.add("제주");
		add(list);
		
		label1 = new Label("이미지 캔버스 : ", Label.CENTER);
		imgCanvas = new Canvas();
		imgCanvas.setBackground(Color.yellow);
		imgCanvas.setSize(200, 150);
		add(label1);
		add(imgCanvas);
		
		lb0 = new Label("종료 버튼 : ");
		bt0 = new Button("종료");
		add(lb0);
		add(bt0);
		
		setSize(730, 450);
		setVisible(true);
		
		bt0.addActionListener(this);
		list.addItemListener(this);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		todo03 c1 = new todo03();
	}
	
	public void actionPerformed(ActionEvent evt){
		String str = evt.getActionCommand();
		if(str.equals("종료"))
			System.exit(0);
	}
	
	public void itemStateChanged(ItemEvent ie){
		String str = list.getSelectedItem();
		imgCanvas.setBackground(Color.green);
		if(str.equals("천안")){
			imgCanvas.setBackground(Color.green);
		} else if(str.equals("당진")){
			imgCanvas.setBackground(Color.blue);
		} else if(str.equals("속초")){
			imgCanvas.setBackground(Color.yellow);
		} else if(str.equals("서울")){
			imgCanvas.setBackground(Color.pink);
		} else if(str.equals("제주")){
			imgCanvas.setBackground(Color.magenta);
		}
	}
	
	public void adjustmentValueChanged(AdjustmentEvent ae){
		imgCanvas.setBackground(Color.green);
		imgCanvas.repaint();
	}
	
}
